import re
from common.handle_conf import conf


def replace_data(data, cls):
    """
    :param data: 从excel读取的可能要替换的数据
    :param cls: 类名
    :return:
    """
    while re.search('#(.+?)#', data):
        res = re.search('#(.+?)#', data)
        item = res.group()
        attr = res.group(1)
        try:
            replace_value = getattr(cls, attr)
        except AttributeError:
            replace_value = conf.get('test_data', attr)
        # 进行替换
        data = data.replace(item, str(replace_value))
    return data
